//
//  Array2D.swift
//  TetrisGame
//
//  Created by mac on 2020/11/23.
//

import Foundation


/// Array2D<T>
class Array2D<T> {
    var columns:Int = 0
    var rows:Int = 0
    
    var array:Array<T?>
    
    
    //MARK: -
    init(columns:Int,rows:Int) {
        self.columns = columns
        self.rows = rows
        
        array = Array<T?>.init(repeating: nil, count: columns * rows)
    }
    
    subscript(column:Int,row:Int) -> T? {
        get{
            return array[(row * column) + column]
        }
        set(newValue){
            array[(row * column) + column] = newValue
        }
    }
}
